package com.mozai.shopping.utils.bean;

import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class ComonQueryBean {
    @NotNull(message = "每页数量不能为空")
    private Integer pageSize;

    //页数
    @NotNull(message = "每页页数不能为空")
    private Integer pageNum;

    //起始  Start
    private Integer start;
    //总数量 total
    private Integer total;
    //总页数  totalPage
    private  Integer totalPage;

    public static Integer calculateTotalPage(ComonQueryBean comonQueryBean){
        if (comonQueryBean.getTotal() !=null &&comonQueryBean.getPageSize() !=null){
            if (comonQueryBean.getTotal()% comonQueryBean.getPageSize() !=0){
                return  comonQueryBean.getTotal()/comonQueryBean.getPageSize()+1;
            }else {
                return comonQueryBean.getTotal()/ comonQueryBean.getPageSize();
            }
        }
        return -1;
    }


    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }
}
